import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
import React, { useState } from "react";
import classes from "./referral.module.less";
import { matchTheme } from "../../utils";
import useServices from "../../hooks/useRequest";
import { useDispatch, useSelector } from "react-redux";
import CustomInput from "../../compoents/input";
import toast from "../../compoents/toast";
import { useLockFn } from "ahooks";
import { addInviter } from "../../api/user";
import classNames from "classnames";
import { LocalKeyMap } from "../../local";
import { useTranslation } from "react-i18next";
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
function Referral() {
    var theme = useSelector(function(state) {
        return state.app.theme;
    });
    var dispatch = useDispatch();
    var _useState = _sliced_to_array(useState(""), 2), code = _useState[0], setCode = _useState[1];
    var services = useServices({
        addInviter: addInviter
    });
    var t = useTranslation().t;
    var confirm = useLockFn(/*#__PURE__*/ _async_to_generator(function() {
        return _ts_generator(this, function(_state) {
            if (!code) {
                skip();
                return [
                    2
                ];
            }
            services.addInviter(code).then(function(res) {
                if (res.code == 200) {
                    dispatch.app.setInviter().then(function() {
                        return skip();
                    });
                } else {
                    // toast.common({
                    //   title: res.msg || t(LocalKeyMap.error),
                    //   className: classes.referral_toast,
                    // });
                    toast.createToast({
                        message: res.msg || t(LocalKeyMap.error),
                        type: "errToast"
                    });
                }
            });
            return [
                2
            ];
        });
    }));
    var skip = function() {
        dispatch.app.PUSH("/home");
    };
    return /*#__PURE__*/ _jsxs("div", {
        className: classes.referral,
        children: [
            /*#__PURE__*/ _jsxs("div", {
                className: classes.header,
                children: [
                    /*#__PURE__*/ _jsx("div", {
                        onClick: function() {
                            dispatch.app.BACK();
                        },
                        className: classes.back,
                        children: /*#__PURE__*/ _jsx("img", {
                            src: matchTheme(theme, {
                                light: require("../../assets/icons/light/back.svg"),
                                dark: require("../../assets/icons/light/back.svg")
                            })
                        })
                    }),
                    /*#__PURE__*/ _jsx("div", {
                        className: classes.logo,
                        children: /*#__PURE__*/ _jsx("img", {
                            src: matchTheme(theme, {
                                light: require("../../assets/icons/light/logo.svg"),
                                dark: require("../../assets/icons/dark/logo.svg")
                            })
                        })
                    })
                ]
            }),
            /*#__PURE__*/ _jsxs("div", {
                className: classes.content,
                children: [
                    /*#__PURE__*/ _jsx("img", {
                        src: require("../../assets/icons/referralCode.png"),
                        className: classes.referral_img
                    }),
                    /*#__PURE__*/ _jsx("div", {
                        className: classes.desc,
                        children: t(LocalKeyMap["referral.desc"])
                    }),
                    /*#__PURE__*/ _jsx(CustomInput, {
                        value: code,
                        onChange: setCode,
                        placeholder: t(LocalKeyMap["referral.placeholder"]),
                        className: classes.input,
                        maxLength: 10,
                        classes: {
                            input: classes.i
                        }
                    }),
                    /*#__PURE__*/ _jsx("div", {
                        className: classNames(classes.btn),
                        onClick: confirm,
                        children: code ? t(LocalKeyMap.done) : t(LocalKeyMap.skip)
                    })
                ]
            })
        ]
    });
}
export default Referral;

 //# sourceMappingURL=index.js.map